import uuid, os, requests, json, re, time, datetime, random, hashlib, xml
from django.db.models import F, Q
from rest_framework import serializers, status, generics, mixins, viewsets
from rest_framework.views import APIView
from rest_framework.viewsets import ModelViewSet, GenericViewSet
from rest_framework.response import Response
from rest_framework.filters import SearchFilter, OrderingFilter
from django_filters.rest_framework import DjangoFilterBackend
from functools import reduce
from urllib.parse import unquote_plus
from decimal import Decimal
from django.conf import settings
# 缓存配置
from django.core.cache import cache
from .models import *
from .serializers import *


class TestView(APIView):
    def get(self, request):
        '''
        测试接口
        '''
        try:
            json_data = {"message": "ok", "errorCode": 0, "data": {}}
            is_open = request.GET.get('is_open')
            if is_open == 'mytestkey':
                json_data['message'] = '开始了测试'
                # 测试cache
                # timeout=0 立即过期 timeout=None 永不超时
                cache.set("key", "value", timeout=None)
                print(cache.get('key'))
            return Response(json_data)
        except Exception as e:
            print('发生错误：',e)
            return Response({"message": "出现了无法预料的view视图错误：%s" % e, "errorCode": 1, "data": {}})